package 力扣日常刷题.木22一月.第17天0129;

import java.util.Arrays;

/**
 * @author 帅小伙
 * @date 2022/1/29
 * @description
 */
public class Demo32简单数组差的绝对值为K的数对数目 {

    public int countKDifference(int[] nums, int k) {
        Arrays.sort(nums);
        int ans = 0;
        for (int i = 0; i < nums.length; i++) {
            for (int j = i+1; j < nums.length; j++) {
                if(nums[j] - nums[i] > k) break;
                if(nums[j] - nums[i] == k) ans++;
            }
        }
        return ans;
    }

}
